/**
 * Mar 30, 2010
 */
package org.tomale.id.oracle;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Locale;

import oracle.jdbc.pool.OracleDataSource;

import org.tomale.id.IConnectionProvider;
import org.tomale.id.ProviderException;

/**
 * @author ferd
 *
 */
public class ConnectionProvider implements IConnectionProvider {

	private Connection _cn;
	
	/* (non-Javadoc)
	 * @see org.tomale.id.IConnectionProvider#getConnection(java.lang.String, java.lang.String, java.lang.String)
	 */
	@Override
	public Connection getConnection(String url, 
			String user, String password) throws ProviderException {
		if(url.isEmpty() | user.isEmpty() | password.isEmpty()){
			Locale.setDefault(Locale.ENGLISH);
			try {			
				OracleDataSource ds = new OracleDataSource();
				
				ds.setURL(url);
				ds.setUser(user);
				ds.setPassword(password);
				
				_cn = ds.getConnection();
				
				_cn.setAutoCommit(false);
			} catch(SQLException e){
				throw new ProviderException("Unable to obtain database connection.",
						e);
			}
		} else {
			throw new ProviderException("Connection url, user and password cannot be empty.");
		}
		
		return null;
	}

}
